package com.geovis.emergency.spd.entity.pc.handler;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.postgresql.util.PGobject;

import java.io.IOException;

/**
 * <p>
 *
 * </p>
 *
 * @author Lonsho
 * @version 1.0
 * @date 2022/6/17
 */
public class PgObjectJsonSerializer extends JsonSerializer<PGobject> {
    public static final String JSON_TYPE = "json";
    @Override
    public void serialize(PGobject pGobject, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        if (ObjectUtil.isNotNull(pGobject)){
            if(!pGobject.isNull() && JSON_TYPE.equals(pGobject.getType())){
                jsonGenerator.writeObject(JSONUtil.parse(pGobject.getValue()));
            }

        }
    }
}
